package com.ruoyi.project.system.card.type.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.card.type.domain.CardType;
import com.ruoyi.project.system.card.type.service.ICardTypeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 银行卡类别Controller
 * 
 * @author f_baisi
 * @date 2020-08-26
 */
@Controller
@RequestMapping("/system/card/type")
public class CardTypeController extends BaseController
{
    private String prefix = "system/type";

    @Autowired
    private ICardTypeService cardTypeService;

    @RequiresPermissions("system:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询银行卡类别列表
     */
    @RequiresPermissions("system:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CardType cardType)
    {
        startPage();
        List<CardType> list = cardTypeService.selectCardTypeList(cardType);
        return getDataTable(list);
    }

    /**
     * 导出银行卡类别列表
     */
    @RequiresPermissions("system:type:export")
    @Log(title = "银行卡类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CardType cardType)
    {
        List<CardType> list = cardTypeService.selectCardTypeList(cardType);
        ExcelUtil<CardType> util = new ExcelUtil<CardType>(CardType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 新增银行卡类别
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存银行卡类别
     */
    @RequiresPermissions("system:type:add")
    @Log(title = "银行卡类别", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CardType cardType)
    {
        return toAjax(cardTypeService.insertCardType(cardType));
    }

    /**
     * 修改银行卡类别
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        CardType cardType = cardTypeService.selectCardTypeById(id);
        mmap.put("cardType", cardType);
        return prefix + "/edit";
    }

    /**
     * 修改保存银行卡类别
     */
    @RequiresPermissions("system:type:edit")
    @Log(title = "银行卡类别", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CardType cardType)
    {
        return toAjax(cardTypeService.updateCardType(cardType));
    }

    /**
     * 删除银行卡类别
     */
    @RequiresPermissions("system:type:remove")
    @Log(title = "银行卡类别", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cardTypeService.deleteCardTypeByIds(ids));
    }
}
